<template>
  <!-- 信用量管理 -->
  <div>
    <section class="business-wrapper">
      <el-form
        ref="form"
        :model="queryForm"
        label-width="75px"
        :inline="true"
        class="queryForm more adjustCondition" labelPosition="left"
      >
        <el-row class="business-status search-content" style="display: flex;">
          <el-form-item label="关键字:" >
            <el-input
              v-model="queryForm.keyWord"
              size="large"
              style="width: 400px;margin-left:-15px;"
              placeholder="请输入客户名称/产品名称/合同编号查询"
            ></el-input>
          </el-form-item>
          <el-form-item label="业务状态:" style="margin-left: 50px;">
            <el-select clearable v-model="queryForm.state" placeholder="请选择"  style="width: 320px">
              <el-option
                 v-for="item in $dictUtils.getDictList('busState')"
                 :key="item.value"
                 :label="item.label"
                 :value="item.value">
               </el-option>
          </el-select>
          </el-form-item>
          <el-form-item label="业务类型:" style="margin-left: 50px;">
              <el-select clearable v-model="queryForm.modelId" placeholder="请选择" style="width:175px">
               <el-option
                  v-for="item in processTypeData"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
          </el-form-item>
          <el-form-item>
            <div class="but-container" style="margin-left: 30px;">
              <el-button
                type="primary"
                size="small"
                style="margin-right:5px"
                class="search-btn"
                @click="
                  getList(
                    processType,
                    page,
                    orderBy.name,
                    orderBy.method,
                    queryForm.dateTime,
                    queryForm.state,
                    queryForm.getMoneyType,
                    queryForm.companyName,
                    queryForm.productId,
                    queryForm.modelId,
                    queryForm.dataType,
                    queryForm.keyWord
                  )">查询
              </el-button>
              <el-button size="small" @click="reset">重置</el-button>
            </div>
          </el-form-item>
        </el-row>
      </el-form>
    </section>
    <div class="btn-wrapper">
      <el-button type="primary" @click="goToAddForm" size="small">新增</el-button>
        <section class="right-but adjustRight-but" style="display:flex;margin-bottom:0px">
            <el-button style="cursor:pointer;" type="text"
                       @click="exportExcel(processType,
                  page,
                  orderBy.name,
                  orderBy.method,
                  queryForm.dateTime,
                  queryForm.state,
                  queryForm.getMoneyType,
                  queryForm.companyName,
                  queryForm.productId,
                  queryForm.modelId,
                  queryForm.dataType,
                  queryForm.keyWord)">
                <img src="~@/assets/img/export.png" alt="">
            </el-button>
            <el-button type="text"  style="margin-right:-13px;cursor:pointer;" @click="refreshList">
                <img style="width:44px;height:36px;" src="~@/assets/img/refresh.png" >
            </el-button>
            <PopoverBut :checkedProps="checkedProps"  :options="options" @getCheckeds="handlerCloumn"></PopoverBut>
        </section>
    </div>
    <el-table
      size="mini"
      v-loading="loading"
      :data="tableData"
      style="width: 100%; margin-top: 10px"
      border
      :header-cell-style="{
        'background-color': '#eeeeee !important',
      }"
      :row-class-name="tableRowClassName"
      @selection-change="tableSelected"
      @sort-change="sortthiscolumn">
      <el-table-column
        type="selection"
        width="60">
      </el-table-column>
      <el-table-column type="index" label="序号" width="70" align="center">
        <template slot-scope="scope">
          <span>{{
              (page.pageNo - 1) * page.pageSize + scope.$index + 1
            }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" label="业务编号" width="230">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false" style="padding-right: 10px" @click="getSettingClient(scope.row,'业务详情')">{{scope.row.codes}}</el-link>
        </template>
      </el-table-column>

      <el-table-column prop="modelName" sortable="custom" label="业务类型" width="140"></el-table-column>
      <el-table-column prop="productNames"  :label="productValue" width="140" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              {{scope.row.productNames | noValue}}
          </template>
      </el-table-column>
      <el-table-column prop="companyName" sortable="custom" :label="companyValue" width="150"></el-table-column>
      <el-table-column prop="productName" sortable="custom" label="数量" min-width="130">
        <template slot-scope="scope">
          <p><span class="mark total">总</span>{{ scope.row.quantity  | thousandSep}}</p>
          <p><span class="mark surplus">余</span>{{ scope.row.surpQuantity  | thousandSep}}</p>
        </template>
      </el-table-column>

      <el-table-column prop="smoney" sortable="custom" align="left" label="金额" min-width="130">
        <template slot-scope="scope">
          <p><span class="mark total">总</span>{{ scope.row.smoney | thousandSep}}</p>
          <p><span class="mark surplus">余</span>{{ scope.row.surpMoney | thousandSep}}</p>
        </template>
      </el-table-column>

      <el-table-column prop="state" label="状态" sortable="custom" width="120" align="center">
        <template slot-scope="scope">
          <div class="state" v-if=" scope.row.state === -1"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state empty" v-if=" scope.row.state === 1"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state process" v-if=" scope.row.state === 2" ><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state process" v-if=" scope.row.state === 3 || scope.row.state === 4 " type="danger"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state normal" v-if=" scope.row.state === 100"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state normal" v-if=" scope.row.state === 101"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state normal" v-if=" scope.row.state === 102"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
          <div class="state normal" v-if=" scope.row.state === 103"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.state, "")}}</div>
        </template>
      </el-table-column>
      <span v-for="(item, index) in checkedProps" :key="index">
        <el-table-column prop="createBy.loginName" min-width="110px" :label="item" v-if="item==='创建人'">
              <template slot-scope="scope">
                  <span v-if="scope.row.createBy && scope.row.createBy.loginName">
                       {{scope.row.createBy.loginName | noValue}}
                  </span>
                  <span v-else>--</span>
              </template>
          </el-table-column>
          <el-table-column prop="createDate" :label="item"  min-width="200px" v-if="item==='创建时间'">
            <template slot-scope="scope">
                {{scope.row.createDate | noValue}}
            </template>
        </el-table-column>
        <el-table-column prop="updateBy.loginName" min-width="120px" :label="item" v-if="item==='上次操作人'">
              <template slot-scope="scope">
                  <span v-if="scope.row.updateBy && scope.row.updateBy.loginName">
                     {{scope.row.updateBy.loginName | noValue}}
                  </span>
                  <span v-else>--</span>
              </template>
          </el-table-column>
          <el-table-column prop="updateDate" :label="item"  min-width="200px" v-if="item==='上次操作时间'">
              <template slot-scope="scope">
                  {{scope.row.updateDate | noValue}}
              </template>
          </el-table-column>
          <el-table-column prop="dataType"  :label="item" v-if="item === '数据类别'" sortable="custom" width="130">
        <template slot-scope="scope">
          {{ $dictUtils.getDictLabel("dataType", scope.row.dataType, "") | noValue}}
        </template>
      </el-table-column>
          <el-table-column prop="executeStartDate" :label="item" v-if="item === '指定执行时间'" sortable="custom" width="220">
        <template slot-scope="scope">
          {{ scope.row.executeStartDate | noValue}} ~ {{ scope.row.executeEndDate | noValue}}
        </template>
      </el-table-column>
      </span>

      <el-table-column prop="address" label="执行情况" width="122">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false" style="padding-right: 10px" @click="openInfo(scope.row.id)">{{ scope.row.weightNumber }}</el-link>

        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作" width="158">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false" style="padding-right: 10px" @click="getSettingClient(scope.row,'设置')">设置</el-link>
             <el-dropdown @command="handleCommand($event,scope.row)">
               <span class="el-dropdown-link">
               更多<i class="el-icon-arrow-down el-icon--right"></i>
               </span>
               <el-dropdown-menu slot="dropdown">
                 <el-dropdown-item command="edit" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 1)" >修改</el-dropdown-item>
                 <el-dropdown-item command="del" v-if="hasPermission('busin:busin:del') && (scope.row.state === 1)">删除</el-dropdown-item>
                 <el-dropdown-item command="confirm" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 1)">提交</el-dropdown-item>
                 <el-dropdown-item  command="clear" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 101  || scope.row.stat===100)">中止</el-dropdown-item>
                 <el-dropdown-item  command="finish" v-if="hasPermission('busin:busin:edit')  && (scope.row.state === 101  || scope.row.stat===100)">完成</el-dropdown-item>
                 <el-dropdown-item  command="stop" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 100)">暂停</el-dropdown-item>
                 <el-dropdown-item  command="recovery" v-if="hasPermission('busin:busin:edit')  && (scope.row.state === 101)">恢复</el-dropdown-item>
                 <el-dropdown-item  command="continue" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 100  || scope.row.stat===101 || scope.row.stat===102 || scope.row.stat===103)">续签</el-dropdown-item>
                 <el-dropdown-item  command="withdraw" v-if="hasPermission('busin:busin:edit') && (scope.row.state === 3)">撤回</el-dropdown-item>
               </el-dropdown-menu>
             </el-dropdown>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-size="page.pageSize"
      :current-page="page.pageNo"
      layout="total,sizes,prev, pager, next, jumper"
      :total="page.total"
    >
    </el-pagination>
    <!--产品选择弹窗-->
    <ProductDialog ref="ProductDialog" @getProductData="getProductData">

    </ProductDialog>
    <!--客户选择弹窗-->
    <CompanyDialog ref="CompanyDialog" @getCompanyData="getCompanyData">

    </CompanyDialog>
    <!--相关设置弹窗-->
    <BusinessDialog ref="BusinessDialog"  :businessId="this.businessId" :procInsId="this.procInsId">

    </BusinessDialog>

      <el-dialog
          title="执行明细"
          :visible.sync="innerVisible"
          class="tableDialog"
          append-to-body>
          <span>
              已过磅 {{weightNumber}}车      合计 {{weightTon}}吨        剩余数量 {{ surplusWeightTon }} 吨
          </span>
          <el-table
              size="mini"
              v-loading="infoLoading"
              :data="infoListData"
              style="width: 100%; margin-top: 10px"
              border
              :header-cell-style="{
        'background-color': '#eeeeee !important',
      }">


              <el-table-column type="index" label="序号" width="60" align="center">
                  <template slot-scope="scope">
          <span>{{
                  (page.pageNo - 1) * page.pageSize + scope.$index + 1
              }}</span>
                  </template>
              </el-table-column>
              <el-table-column
                  label="过磅日期"
                  prop="weightTime"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="过磅单"
                  prop="weightCode"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="货物名称"
                  prop="productName"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="车牌号"
                  prop="truckNumber"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="车牌号"
                  prop="driverName"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="单价"
                  prop="productPrice"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="数量"
                  prop="productPrice"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="金额"
                  prop="productPrice"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
              <el-table-column
                  label="支付方式"
                  prop="payMode"
                  :show-overflow-tooltip="true"
              >
                  <template slot-scope="scope">
                      {{ $dictUtils.getDictLabel("payMode", scope.row.payMode, "") }}
                  </template>
              </el-table-column>
              <el-table-column prop="paymentState" label="支付状态" sortable="custom" width="100" align="center">
                  <template slot-scope="scope">
                      <div class="state" v-if=" scope.row.paymentState === -1"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.paymentState, "")}}</div>
                      <div class="state empty" v-if=" scope.row.paymentState === 1"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.paymentState, "")}}</div>
                      <div class="state process" v-if=" scope.row.paymentState === 2" ><span></span>{{$dictUtils.getDictLabel("busState", scope.row.paymentState, "")}}</div>
                      <div class="state process" v-if=" scope.row.paymentState === 3 || scope.row.paymentState === 4 " type="danger"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.paymentState, "")}}</div>
                      <div class="state normal" v-if=" scope.row.paymentState === 100"><span></span>{{$dictUtils.getDictLabel("busState", scope.row.paymentState, "")}}</div>
                  </template>
              </el-table-column>
              <el-table-column
                  label="支付时间"
                  prop="paymentTime"
                  :show-overflow-tooltip="true"
              >
              </el-table-column>
          </el-table>
          <el-pagination
              background
              @size-change="infoHandleSizeChange"
              @current-change="infoHandleCurrentChange"
              :page-size="infoPage.pageSize"
              :current-page="infoPage.pageNo"
              layout="total,prev, pager, next"
              :total="infoPage.total"
          >
          </el-pagination>

      </el-dialog>
  </div>
</template>
<script>
    import {
        getBusinessList,
        updateBusinessState,
        deleteBusiness,
        getStateById,
        getModelInfo,
        confirmBusiness,
        getBusinessInfoList
    } from '@/api/business/business.js';
  import {getDictModelList,getBusControlVar} from '@/api/model/model.js'
  import PopoverBut from '@/components/button/popoverBut'
  import ProductDialog from '@/components/dialog/productDialog.vue'
  import CompanyDialog from '@/components/dialog/companyDialog.vue'
  import BusinessDialog from '@/components/dialog/businessDialog.vue'

  const options1 = []
  const cityOptions = ['上海', '北京']
  export default {
    components: {
      // EditForm,
      ProductDialog,
      //TimeSelect,
      CompanyDialog,
      BusinessDialog,
      PopoverBut
    },
    inject: ["processType"],
    data () {
      return {
          innerVisible: false,
          businessId: '',
          infoResData:{},

        businessIds: [], // 选中的数据id数组
        businessId:'',
        procInsId:'',
        modelId:'',
        modelIds: [], // 选中的数据modelId数组
        processTypeData: [],
        productValue: "产品",
        companyValue: "客户",
        ckecked: '',
        value3:'',
        value4:'',
        queryForm: {
          keyWord: '',
          modelId: '',
          dateTime: [],

          state: '',
          getMoneyType: '',
          dataType: '',
          contractCode: '',
          companyId: '',
          companyName: '',
          productId: '',
          productName: '',
          checkedState: '1',
          name: ''
        },
        value2: '',
        checkedProps: options1,
        ShowCloum: {createDate: ''},
        options: [
          {label: '数据类别', key: 'dataType'},
          {label: '指定执行时间', key: 'executeStartDate'},
          {label: '创建人', key: 'createBy.loginName'},
          {label: '创建时间', key: 'createDate'},
          {label: '上次操作人', key: 'updateBy.loginName'},
          {label: '上次操作时间', key: 'updateDate'}
        ],
        tableData: [],
          infoListData: [],
          weightNumber: 0,
          weightTon: '',
          surplusWeightTon: 0,
        orderBy: {
          name: 'create_date',
          method: 'desc'
        },
        loading: false,
        infoLoading: false,
        page: {
          pageSize: 10,
          pageNo: 1,
          total: 0
        },
          infoPage: {
              pageSize: 10,
              pageNo: 1,
              total: 0
          },
        props: 1,
        checkedCities: [],
        cities: cityOptions
      }
    },

    methods: {
      getTime1(e){
        this.value3=e.startTime;
        this.value4=e.endTime;
      },

        refreshList () {
            this.getList(
                this.processType,
                this.page,
                this.orderBy.name,
                this.orderBy.method,
                this.queryForm.dateTime,
                this.queryForm.state,
                this.queryForm.getMoneyType,
                this.queryForm.companyName,
                this.queryForm.productId,
                this.queryForm.modelId,
                this.queryForm.dataType,
                this.queryForm.keyWord
            )
        },
        // 是否显示某列数据
        handlerCloumn (e) {
            this.checkedProps = e
        },
      // 多选
      tableSelected (val) {
        // 去重获取被选中的id值存入到数组中
        this.businessIds = []
        this.modelIds = []
        for (let selectedItem of val) {
          this.businessIds.push(selectedItem.id)
          this.modelIds.push(selectedItem.modelId)
        }
      },
      //更多操作
      handleCommand($event,row){
        console.log(row)
        if($event=="edit"){
          this.edit(row.id)
        }else if($event=="del"){
          this.del(row.id)
        }else if($event=="confirm"){
          this.confirm(row.id)
        }else if($event=="clear"){
          this.updateState(row.id,103)
        }else if($event=="finish"){
          console.log("finsish")
          this.updateState(row.id,102)
        }else if($event=="stop"){
          this.updateState(row.id,101)
        }else if($event=="recovery"){
          this.updateState(row.id,100)
        }else if($event=="continue"){
          this.updateState(row.id,999)
        }else if($event=="withdraw"){
          // this.updateState(row.id,103)
        }
      },
      confirm(id){
        confirmBusiness({
            id: id
          }).then((res) => {
            if (res.data.code === '200') {
              this.$message({
                type: 'success',
                message: res.data.message
              })
            } else {
              this.$message({
                type: 'error',
                message: res.data.message
              })
            }
            this.loading = false
          })
      },
      // 导出
      exportExcel (processType, params, orderName, orderByAORC, queryDateTime, queryState, getMoneyType, companyName, productId, modelId, dataType, keyWord) {
        this.$http({
          method: 'get',
          url: '/business/export',
          params: {
            processType: processType,
            pageSize: params.pageSize,
            pageNo: params.pageNo,
            orderBy: orderName,
            orderByAORC: orderByAORC,
            contractStartDate: this.value3,
            contractEndDate: this.value4,
            state: queryState,
            getMoneyType: getMoneyType,
            companyName: companyName,
            productId: productId,
            modelId: modelId,
            dataType: dataType,
            keyWord: keyWord
          },
          responseType: 'blob'
        }).then(response => {
          if (!response) {
            return
          }
          let link = document.createElement('a')
          link.href = window.URL.createObjectURL(new Blob([response.data]))
          link.target = '_blank'
          let filename = response.headers['content-disposition']
          link.download = decodeURI(filename)
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
          // eslint-disable-next-line handle-callback-err
        }).catch((error) => {

        })
      },
      // 状态修改
      updateState (id,state) {
          var str = '';

          if (state === 101) { // 暂停
            str = '暂停后，该业务将不可用！确定要暂停吗？';
            this.update(str,id,state)
          } else if (state === 100){ // 恢复
            str = '恢复后，该业务可被继续使用！确定要恢复吗？';
            this.update(str,id,state)
          }else if (state === 102){ // 完成

            str = '确认完成该业务吗？';
            this.update(str,id,state)
          } else if (state === 999){ // 完成
              getStateById({
                  id: id
              }).then((res) => {
                  if (res.data.code === '200') {
                      if (res.data.result.state === 100) {
                          str = '确认续签该业务吗？';
                          this.update(str,id,state)
                      } else {
                          this.$notify.error({
                              title: '错误',
                              message: this.$dictUtils.getDictLabel("busState", res.data.result.state, "")+'该状态不支持续签！'
                          })
                      }
                  }
                  this.loading = false
              })
          }else if (state === 103) { // 中止
          console.log(103)
            getBusControlVar({
              businessId: id
            }).then((res) => {
              if (res.data.code === "200") {
                if (res.data.result.svalue === '1') {
                  str = '中止操作后，业务余量将不可用，确定要中止吗？';
                }else if (res.data.result.svalue === '2') {
                  str = '中止操作后，业务余额将自动结转至活动余额中，同时改业务将不可用，确定要中止吗？';
                }else if (res.data.result.svalue === '3') {
                  str = '中止操作后，业务将不可用，确定要中止吗？';
                }
                this.update(str,id,state)
              }
            })
          }
      },

      update (str,businessId,state) {
        console.log(str);
        this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then((res) => {
          updateBusinessState({
            state: state,
            ids: businessId
          }).then((res) => {
            this.loading = true;
            if (res.data.code === '200') {
              this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
              this.$message({
                type: 'success',
                message: '状态修改成功'
              })
            } else {
              this.$message({
                type: 'error',
                message: res.data.message
              })
            }
            this.loading = false
          })
        })
      },
      // 删除业务
      del (id) {
          getStateById({
            id: id
          }).then((res) => {
            if (res.data.code === '200') {
              if (res.data.result.state === 1) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then((res) => {
                  deleteBusiness({
                    ids: id
                  }).then((res) => {
                    if (res.data.code === '200') {
                      this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
                      this.$message({
                        type: 'success',
                        message: '删除成功'
                      })
                    } else {
                      this.$message({
                        type: 'error',
                        message: res.data.message
                      })
                    }
                    this.loading = false
                  })
                });
              } else {
                this.$notify.error({
                  title: '错误',
                  message: this.$dictUtils.getDictLabel("busState", res.data.result.state, "")+'该状态不支持删除！'
                })
              }
            }
            this.loading = false
          })

      },
    goToAddForm () {
      var name=''
      if(this.processType==1){
        name='新增销售业务'
      }else if(this.processType==2){
        name='新增采购业务'
      }else{
        name='新增其他业务'
      }
      this.processType
      this.$router.push({path:'/business/business/addBusinessView',query:{title:name,processType:this.processType
      }})
    },
      // 客户选择弹窗
      getCompanyClient () {
        this.$refs['CompanyDialog'].dialogVisible = true
      },
      // 客户选择数据回显
      getCompanyData (row) {
        this.queryForm.companyName = row.names
        this.queryForm.companyId = row.id
        this.dialogVisible = false
      },
      // 产品选择弹窗
      getProductClient () {
        this.$refs['ProductDialog'].page.pageNo = 1
        this.$refs['ProductDialog'].getProductList(10,1)
        this.$refs['ProductDialog'].dialogVisible = true
      },
      getProductData (row) {
        this.queryForm.productName = row.name
        this.queryForm.productId = row.id
        this.dialogVisible = false
        console.log(row)
      },
        // 执行明细弹窗
        openInfo(businessId) {
            this.innerVisible = true;
            this.businessId = businessId;
            this.getInfoList(businessId,this.infoPage);
        },
      // 相关设置弹窗
      getSettingClient (row,title) {
        this.businessId=row.id
        this.modelId=row.modelId
        this.procInsId = row.procInsId || ''
          console.log('相关设置弹窗')
          console.log(this.businessId)
          console.log(this.modelId)
          this.$refs['BusinessDialog'].init(title)
      },
      // 相关设置弹窗
      edit (id) {
          console.log('相关设置弹窗')
          getStateById({
            id: id
          }).then((res) => {
            if (res.data.code === '200') {
              // var state = s.getDictLabel("busState",res.data.result.state, "")
              if (res.data.result.state === 1) {
                this.$router.push({path: '/form/template', query: {title: res.data.result.modelName, id: res.data.result.modelId, previewMode: true, method:'edit',businessId:id}})
              } else {
                this.$notify.error({
                  title: '错误',
                  message: this.$dictUtils.getDictLabel("busState", res.data.result.state, "")+'该状态不支持修改！'
                })
              }
            }
            this.loading = false
          })
      },
      // 获取列表带分页
      getList (processType, params, orderName, orderByAORC, queryDateTime, queryState, getMoneyType, companyName, productId, modelId, dataType, keyWord) {
        this.loading = true
        getBusinessList({
          processType: processType,
          pageSize: params.pageSize,
          pageNo: params.pageNo,
          orderBy: orderName,
          orderByAORC: orderByAORC,
          contractStartDate: this.value3,
          contractEndDate: this.value4,
          state: queryState,
          allState:2,//未生效
          getMoneyType: getMoneyType,
          companyName: companyName,
          productId: productId,
          modelId: modelId,
          dataType: dataType,
          keyWord: keyWord
        }).then((res) => {
          if (res.data.code === '200') {
            this.tableData = res.data.result.list
            this.page.total = res.data.result.count
          }
          this.loading = false
        })
      },
        // 获取列表带分页
        getInfoList (businessId, params) {
            this.infoLoading = true
            getBusinessInfoList({
                businessId: businessId,
                pageSize: params.pageSize,
                pageNo: params.pageNo
            }).then((res) => {
                if (res.data.code === '200') {
                    this.weightNumber = res.data.result.weightNumber
                    this.weightTon = res.data.result.weightTon
                    this.surplusWeightTon = res.data.result.surplusWeightTon
                    this.infoListData = res.data.result.page.list
                    this.infoPage.total = res.data.result.page.count


                }
                this.infoLoading = false
            })
        },
      // 获取业务类型字典
      getDictModelList (processType) {
        this.loading = true
        getDictModelList({
          processType: processType
        }).then((res) => {
          if (res.data.code === '200') {
            this.processTypeData = res.data.result
          }
          this.loading = false
        })
      },
      // 重置查询条件
      reset () {
        this.queryForm.modelId = ''
          this.queryForm.dateTime = ''
          this.queryForm.state = ''
          this.queryForm.getMoneyType = ''
          this.queryForm.dataType = ''
          this.queryForm.contractCode = ''
          this.queryForm.companyId = ''
          this.queryForm.companyName = ''
          this.queryForm.productId = ''
          this.queryForm.productName = ''
          this.queryForm.checkedState = ''
          this.queryForm.name = ''
          this.value3=''
          this.value4=''
          this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
      },
      // 排序
      sortthiscolumn (a) {
        this.orderBy.name = a.prop
        this.page.pageNo = 1
        if (a.order === 'ascending') {
          this.orderBy.method = 'asc'
        } else {
          this.orderBy.method = 'desc'
        }
        this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
      },
      handleSizeChange (e) {
        this.page.pageSize = e
        this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
      },
      handleCurrentChange (e) {
        this.page.pageNo = e
        this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
        console.log(e)
      },
        infoHandleSizeChange (e) {
            this.infoPage.pageSize = e
            this.getInfoList(this.businessId, this.infoPage)
        },
        infoHandleCurrentChange (e) {
            this.infoPage.pageNo = e
            this.getInfoList(this.businessId, this.infoPage)
            console.log(e)
        },
      tableRowClassName ({row, rowIndex}) {
        if (rowIndex % 2 === 1) {
          return 'warning-row'
        } else {
          return 'success-row'
        }
      }
    },
    mounted () {
      // this.tableData = [{ names: '1' }]
      if(this.processType==1){
        this.productValue='产品'
        this.companyValue='客户'
      }else if(this.processType==2){
        this.productValue='原料'
        this.companyValue='供应商'
      }
      this.getList(this.processType, this.page, this.orderBy.name, this.orderBy.method)
    this.getDictModelList(1)
    }
  }

</script>
<style scoped lang="scss">
  @import './index.scss';
</style>
